package com.ddxz.hospital.util;

import com.ddxz.hospital.dto.TreatPlan;
import com.ddxz.tool.core.convert.StringUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * class description
 *
 * @author 朱宗刚
 * @version 1.0.0
 * @date 2020/9/23
 */

public class Desc2Code {
    public static Integer getGenderCode(String desc) {
        return null != desc && !desc.isEmpty() ? "男".equals(desc) ? 1 : 2 : 1;
    }

    public static String getHospitalNo(String desc) {
        String tmp = desc.trim();
        int length = 10 - tmp.length();

        StringBuilder builder;
        for(builder = new StringBuilder(tmp); length > 0; --length) {
            builder.insert(0, '0');
        }

        return builder.toString();
    }

    public static Integer getNation(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "汉族":
                return 1;
            case "不详":
                return 3;
            default:
                return 2;
        }
    }

    public static Integer getRelation(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "父亲":
                return 1;
            case "母亲":
                return 2;
            default:
                return 3;
        }
    }

    public static Integer getDietaryStatus(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "严格糖尿病饮食":
                return 1;
            case "基本糖尿病饮食":
                return 2;
            case "随意":
                return 3;
            default:
                return 0;
        }
    }

    public static Integer getMotionCondition(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "无":
                return 1;
            case "偶尔":
                return 2;
            case "每天有规律运动":
                return 3;
            default:
                return 0;
        }
    }

    public static Integer getMentalHealth(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "无不适":
                return 1;
            case "轻度障碍":
                return 2;
            case "中度障碍":
                return 3;
            case "重度障碍":
                return 4;
            default:
                return 0;
        }
    }

    public static Integer getDamage(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "良好":
                return 1;
            case "轻度损害(≤2处)":
                return 2;
            case "中重度损害(≥3处)":
                return 3;
            case "硬结":
                return 4;
            case "鼓包":
                return 5;
            case "脂肪萎陷":
                return 6;
            default:
                return 0;
        }
    }

    public static Integer getFrequence(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "无":
                return 1;
            case "偶尔":
                return 2;
            case "频繁":
                return 3;
            default:
                return 0;
        }
    }

    public static Integer getLevel(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "P3-10":
                return 2;
            case "P10-25":
                return 3;
            case "P25-50":
                return 4;
            case "P50-75":
                return 5;
            case "P75-90":
                return 6;
            case "P90-95":
                return 7;
            case "≥P95":
                return 8;
            default:
                return 1;
        }
    }

    public static Integer getAddressType(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "城市":
                return 1;
            case "城镇":
                return 2;
            default:
                return 3;
        }
    }

    public static Integer getInsurance(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "沈阳市居民医保":
                return 1;
            case "农村合作医疗":
                return 2;
            case "异地居民医保":
                return 3;
            case "商业保险":
                return 4;
            default:
                return 5;
        }
    }

    public static Integer getHomeEconomy(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "好":
                return 1;
            case "中":
                return 2;
            default:
                return 3;
        }
    }

    public static Integer getDegree(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "散居":
                return 1;
            case "幼儿园":
                return 2;
            case "小学":
                return 3;
            case "初中":
                return 4;
            default:
                return 5;
        }
    }

    public static Integer getParentDegree(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "初中及以下":
                return 1;
            case "高中":
                return 2;
            case "大专/大学":
                return 3;
            default:
                return 4;
        }
    }

    public static Integer getVocation(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "农民":
                return 1;
            case "工人":
                return 2;
            case "机关企事业单位负责人":
                return 3;
            case "公务员":
                return 4;
            case "商业服务业人员":
                return 5;
            case "专业技术人员":
                return 6;
            default:
                return 7;
        }
    }

    public static Integer getParentRelation(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "良好":
                return 1;
            case "一般":
                return 2;
            default:
                return 3;
        }
    }

    public static Integer getJudge(String desc) {
        return StringUtil.isEmpty(desc) ? 2 : "是".equals(desc) ? 1 : 2;
    }

    public static Integer getWeeks(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "足月":
                return 1;
            case "早产":
                return 2;
            case "过期产":
                return 3;
            default:
                return 4;
        }
    }

    public static Integer getDeliverType(String desc) {
        return null != desc && !desc.isEmpty() ? "顺产".equals(desc) ? 2 : ("不详".equals(desc) ? 3 : 1) : null;
    }

    public static Integer getFeedType(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "母乳喂养":
                return 1;
            case "人工喂养":
                return 2;
            default:
                return 3;
        }
    }

    public static String getDesc(String desc) {
        return null != desc && !desc.isEmpty() ? desc.trim() : null;
    }

    public static Integer getElePlayTime(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "<0.5小时/天":
                return 1;
            case "0.5-2小时/天":
                return 2;
            default:
                return 3;
        }
    }

    public static Integer getSportSituation(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "1次/周(≥30分钟/次)":
                return 1;
            case "1-3次/周(≥30分钟/次)":
                return 2;
            default:
                return 3;
        }
    }

    public static List<Integer> getHistory(String father, String mather, String grandFather, String grandMather, String grandFather1, String grandMather1, String other, String none) {
        return getList(father, mather, grandFather, grandMather, grandFather1, grandMather1, "无".equals(none) ? "有" : "无", other);
    }

    public static Integer getHas(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "有":
                return 1;
            case "无":
                return 2;
            default:
                return 3;
        }
    }

    public static Integer getTimes(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "0":
                return 0;
            case "1":
                return 1;
            case "2":
                return 2;
            case "3":
                return 3;
            default:
                return 4;
        }
    }

    public static Integer getDateTimeUnit(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "天":
                return 2;
            case "周":
                return 3;
            case "月":
                return 4;
            case "年":
                return 5;
            default:
                return 1;
        }
    }

    public static Double getBMI(Double height, Double weight) {
        if (null != height && Math.abs(height) >= 1.0E-6D) {
            return weight == null ? null : 10000.0 * weight / (height * height);
        } else {
            return null;
        }
    }

    public static Double getWaistHeight(Double waist, Double height) {
        if (null != height && Math.abs(height) >= 1.0E-6D) {
            return waist == null ? null : waist / height;
        } else {
            return null;
        }
    }

    public static List<Integer> getSymptom(String w, String x, String y, String z, String aa, String ab, String ac, String ad, String ae, String af, String ag, String ah, String ai, String aj, String ak, String al, String am) {
        return getList(w, x, y, z, aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am);
    }

    public static List<Integer> getDka(String ba, String bb) {
        Integer[] dka = new Integer[5];
        Arrays.fill(dka, 0);
        switch (ba) {
            case "无":
                dka[0] = 1;
                break;
            case "轻度":
                dka[1] = 1;
                break;
            case "中度":
                dka[2] = 1;
                break;
            case "重度":
                dka[3] = 1;
                break;
            default:
                dka[4] = 1;
        }

        switch (bb) {
            case "无":
                dka[0] = 1;
                break;
            case "轻度":
                dka[1] = 1;
                break;
            case "中度":
                dka[2] = 1;
                break;
            case "重度":
                dka[3] = 1;
                break;
            default:
                dka[4] = 1;
        }

        return Arrays.asList(dka);
    }

    private static List<Integer> getList(String... args) {
        int idx = 1;
        List<Integer> list = new ArrayList();
        String[] var4 = args;
        int var5 = args.length;

        for(int var6 = 0; var6 < var5; ++var6) {
            String arg = var4[var6];
            Integer tmp = getHas(arg);
            if (null != tmp && 1 == tmp) {
                list.add(idx);
            } else {
                tmp = getJudge(arg);
                if (null != tmp && 1 == tmp) {
                    list.add(idx);
                }
            }

            ++idx;
        }

        return list.size() > 0 ? list : null;
    }

    public static List<Integer> getSign(String an, String ao, String ap, String aq, String ar, String as, String at, String au, String av, String aw, String ax) {
        return getList(an, ao, ap, aq, ar, as, at, au, av, aw, ax);
    }

    public static Integer getDKA(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "无":
                return 4;
            case "中度":
                return 2;
            case "重度":
                return 3;
            case "轻度":
                return 1;
            default:
                return 5;
        }
    }

    public static Integer getPreconditon(String desc) {
        return null != desc && !desc.isEmpty() ? "随机".equals(desc) ? 2 : 1 : null;
    }

    public static Integer getUrineResult(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "1 +":
                return 1;
            case "2 ++":
                return 2;
            case "3 ++":
                return 3;
            case "0 阴性":
                return 0;
            default:
                return 4;
        }
    }

    public static Integer getAntiResult(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "阳性":
                return 1;
            case "阴性":
                return 2;
            default:
                return 3;
        }
    }

    public static Integer getCTResult(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "正常":
                return 1;
            case "异常":
                return 2;
            default:
                return 3;
        }
    }

    public static List<Integer> getConclusion(String cn, String co, String cp, String cq, String cr, String cs, String ct, String cu, String cv, String cw, String cx, String cy) {
        return getList(cn, co, cp, cq, cr, cs, ct, cu, cv, cw, cx, cy);
    }

    public static Integer getBloodCheck(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "指尖血糖，规律，≥4次/天":
                return 1;
            case "指尖血糖，无规律":
                return 2;
            case "带动态血糖检测，同时联合指尖血糖":
                return 3;
            case "带动态血糖，不测指尖血糖":
                return 4;
            default:
                return 5;
        }
    }

    public static Integer getRecheck(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "≥4次/年":
                return 1;
            case "2-3次/年":
                return 2;
            default:
                return 3;
        }
    }

    public static Integer getInfect(String desc) {
        if(StringUtil.isEmpty(desc)) {
            return null;
        }

        switch (desc) {
            case "呼吸道":
                return 1;
            case "消化道":
                return 2;
            case "皮肤":
                return 3;
            case "其他":
                return 4;
            default:
                return 5;
        }
    }

    public static List<TreatPlan> getTreatPlan(String c, Integer d, String e, String f, Integer g, String h, String i, Integer j, String k, String l, Integer m, String n, String o, Integer p, String q, String r, Integer s, String t, String u) {
        List<TreatPlan> treatList = new ArrayList();
        TreatPlan plan = treatPlanBuilder(c, d, e);
        if (null != plan) {
            plan.setIndex(1);
            treatList.add(plan);
        }

        plan = treatPlanBuilder(f, g, h);
        if (null != plan) {
            plan.setIndex(2);
            treatList.add(plan);
        }

        plan = treatPlanBuilder(i, j, k);
        if (null != plan) {
            plan.setIndex(3);
            treatList.add(plan);
        }

        plan = treatPlanBuilder(l, m, n);
        if (null != plan) {
            plan.setIndex(4);
            treatList.add(plan);
        }

        plan = treatPlanBuilder(o, p, q);
        if (null != plan) {
            plan.setIndex(5);
            treatList.add(plan);
        }

        plan = treatPlanBuilder(r, s, t);
        if (null != plan) {
            plan.setIndex(6);
            treatList.add(plan);
        }

        if ("无".equals(u)) {
            plan = new TreatPlan();
            plan.setIndex(7);
            treatList.add(plan);
        }

        return treatList.size() > 0 ? treatList : null;
    }

    private static TreatPlan treatPlanBuilder(String idx, Integer total, String unit) {
        if (1 == getJudge(idx)) {
            TreatPlan treatPlan = new TreatPlan();
            treatPlan.setTotal(total);
            treatPlan.setUnit(getDateTimeUnit(unit));
            return treatPlan;
        } else {
            return null;
        }
    }

    public static List<Integer> getInsulinType(String z, String aa, String ab, String ac, String ad) {
        List<Integer> insulinType = new ArrayList();
        if (1 == getJudge(z)) {
            insulinType.add(1);
        }

        if (1 == getJudge(aa)) {
            insulinType.add(2);
        }

        if (1 == getJudge(ab)) {
            insulinType.add(3);
        }

        if (1 == getJudge(ac)) {
            insulinType.add(4);
        }

        if (1 == getJudge(ad)) {
            insulinType.add(5);
        }

        return insulinType.size() > 0 ? insulinType : null;
    }
}
